package com.zues.samples.service.Impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zues.samples.dao.TestDAO;
import com.zues.samples.model.PagerModel;
import com.zues.samples.model.Subject;
import com.zues.samples.model.Testmodel;
import com.zues.samples.service.SubjectService;
import com.zues.samples.service.TestmodelService;
import com.zues.samples.service.modelVO.ExamTestOV;
import com.zues.samples.service.modelVO.ExamTestTypeOV;

@Service
public class TestmodelServiceImpl implements TestmodelService{
	
	@Autowired
	private TestDAO testDAO;
	@Autowired
	private SubjectService subjectService;

	@Override
	public List<Testmodel> findAllTest() throws Exception {
		return testDAO.findAllTest();
	}

	@Override
	public void createTest(Testmodel test) throws Exception {
		testDAO.createTest(test);
		
	}

	@Override
	public Testmodel getTestById(int testid) throws Exception {
		return testDAO.getTestById(testid);
	}

	@Override
	public void editTest(Testmodel test) throws Exception {
		testDAO.editTest(test);
	}

	@Override
	public void deleteTest(int testid) throws Exception {
		testDAO.deleteTest(testid);
	}

	@Override
	public ExamTestOV getTestByOneId(Integer testId) throws Exception {
		Testmodel entity = testDAO.getTestById(testId);
		if(entity!=null){
			ExamTestOV vo = new ExamTestOV();
			BeanUtils.copyProperties(entity, vo);
			
			Subject subject = subjectService.getByIdSubject(entity.getSubId());
			if(subject != null){
				vo.setSubName(subject.getName());
			}
			
			ExamTestTypeOV typeOV = new ExamTestTypeOV();
			BeanUtils.copyProperties(entity.getExamTestType(),typeOV );
			vo.setExamTestTypeOV(typeOV);
			return vo;
		}
		return null;
	}

	@Override
	public PagerModel<ExamTestOV> findAllByPage() {
		return testDAO.findAllByPage();
	}
	
	
}
